﻿using System.Collections.Generic;
using Aluetjen.EmailService.Domain.Models.Message;

namespace Aluetjen.EmailService.Domain.Models.Pipeline
{
    public class Redirection : Entity
    {
        public virtual int Id { get; set; }

        public virtual decimal Priority { get; set; }
        public virtual Condition Condition { get; set; }
        public virtual MailAddress RedirectTo { get; set; }
        public virtual bool ClearCc { get; set; }
        public virtual bool ClearBcc { get; set; }

        public virtual void TransformMessage(MailMessage message)
        {
            if (Condition == null || Condition.IsSatisfiedFor(message))
            {
                if (RedirectTo != null)
                {
                    message.To = new List<MailAddress> {RedirectTo};
                }

                if (ClearBcc) message.Bcc.Clear();

                if (ClearCc) message.CC.Clear();
            }
        }
    }
}